package com.bjpowernode.boss.common.client;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.TimeUnit;

@Component
public class RedisClient {

    //String的模板类
    private StringRedisTemplate stringRedisTemplate;

    private HashOperations<String, Object, Object> hashOps;

    public RedisClient( StringRedisTemplate stringRedisTemplate ) {
        this.stringRedisTemplate = stringRedisTemplate;
        hashOps = stringRedisTemplate.opsForHash();
    }

    //定义操作方法
    public Boolean setHashMap(String key, Map<String,String> data, int timeout, TimeUnit timeUnit){
        hashOps.putAll(key,data);
        return stringRedisTemplate.expire(key,timeout,timeUnit);
    }
}
